{% extends "analysis_plugins/general_information.html" %}


{% block styles %}
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/code_pre.css') }}">
    <style>
        .qemu-td {
            width: 100%;
            max-width: 0;
        }
    </style>
{% endblock %}


{% block analysis_result_details %}

    {% if analysis_result.included_file_results %}

        <th class="success" colspan="2">
            Results for Included Files
        </th>

        {% for file_result in analysis_result.included_file_results %}

            <tr data-toggle="collapse" data-target="#collapse-{{ file_result.uid }}">
                <td class="clickable" colspan=2>
                    <i class="fas fa-angle-down"></i> {{ file_result.path }}
                    {% if file_result.is_executable %}
                        <i class="fas fa-check text-success"></i>
                    {% else %}
                        <i class="fas fa-times text-danger"></i>
                    {% endif %}
                </td>
            </tr>

            <tr>
                <td colspan="2" class="qemu-td p-0">
                    <div class="collapse" id="collapse-{{ file_result.uid }}">

                        <table class="table table-bordered m-0" style="width: 100%">
                            <tr>
                                <td style="width: 175px;">Executable in QEMU:</td>
                                <td>{{ file_result.is_executable }}</td>
                            </tr>

                            {% if file_result.extended_results %}
                            <tr>
                                <td>Individual Results:</td>
                                <td class="p-0">
                                    <table class="table table-bordered m-0" style="width: 100%">
                                    {% for arch_result in file_result.extended_results %}
                                        <tr>
                                            {% set rowspan = (arch_result.parameter_results | length) * 3 %}
                                            {% if arch_result.strace != None %}
                                                {% set rowspan = rowspan + 1 %}
                                            {% endif %}
                                            <td style="width: 1px" rowspan="{{ rowspan }}">
                                                {{ arch_result.architecture }}
                                            </td>
                                            {% for option_result in arch_result.parameter_results %}
                                                <td style="width: 1px" rowspan="3">{{ option_result.parameters }}</td>
                                                <td>stdout</td>
                                                <td class="qemu-td" style="padding: 5px;">
                                                    {% if option_result.stdout %}
                                                        <pre class="code-pre">{{ '$ .' + file_result.path + ' ' + option_result.parameters + '\n' + option_result.stdout }}</pre>
                                                    {% else %}
                                                        Empty
                                                    {% endif %}
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>stderr</td>
                                                <td>
                                                    {% if option_result['stderr'] %}
                                                        <pre class="code-pre">{{ '$ .' + file_result.path + ' ' + option_result.parameters + '\n' + option_result.stderr }}</pre>
                                                    {% else %}
                                                        Empty
                                                    {% endif %}
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>return code</td>
                                                <td>{{ option_result.return_code }}</td>
                                            </tr>
                                            <tr>
                                            {% endfor %}
                                            {% if arch_result.strace != None %}
                                                <td style="width: 1px">strace</td>
                                                <td colspan="2">
                                                    {% if arch_result.strace %}
                                                        <pre class="code-pre">{{ arch_result.strace | decompress }}</pre>
                                                    {% else %}
                                                        Empty
                                                    {% endif %}
                                                </td>
                                            </tr>
                                            {% else %}
                                            </tr>
                                            {% endif %}
                                    {% endfor %}
                                    </table>
                                </td>
                            </tr>
                            {% endif %}
                        </table>

                    </div>
                </td>
            </tr>

        {% endfor %}
    {% endif %}

{% endblock %}


{% block ajax %}
    {% set analysis = analysis_result %}

    {% if 'parent_flag' in analysis and analysis.parent_flag == True %}
        <div id="file_results"></div>
        <script>
            $(document).ready(function() {
                $('#file_results').load('/plugins/qemu_exec/ajax/{{ firmware.uid }}');
            });
        </script>
    {% endif %}

{% endblock %}
